package jdbc;

import javax.xml.transform.Result;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection()
        ) {
            Statement statement = connection.createStatement();
            String sql = "select s.name,s.age,s.gender,c.name,c.floor,t.name,t.age,t.salary\n" +
                    "from teacher t \n" +
                    "join class c on t.id = c.teacher_id\n" +
                    "join student s on c.id = s.class_id\n" +
                    "where t.name='刘苍松'";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                String name = rs.getString("s.name");
                int age = rs.getInt("s.age");
                String gender = rs.getString("s.gender");
                String cname = rs.getString("c.name");
                String floor = rs.getString("c.floor");
                String tname = rs.getString("t.name");
                int tage = rs.getInt("t.age");
                int salary = rs.getInt("t.salary");
                System.out.println(name + "," + age + "," + gender + "," + cname + "," + floor + "," + tname + "," + tage + "," + salary);
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
